package com.iman.common.util;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class RandomStr5 {static	String str ="1qghA";

static char[] c1= {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','z','y'  ,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Z','Y' ,             '0','1','2','3','4','5','6','7','8','9'};
static char[] c2= {'M','N','O','P','Q','R','S','T','U','V','W','X','Z','Y' ,'A','B','C','D','E','F','G','H','I','J','K','L','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','z','y'  ,             '0','1','2','3','4','5','6','7','8','9'};
static char[] c3= {'9','8','7','6','5','4','3','2','1','0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','z','y'  ,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Z','Y' ,            };
static char[] c4= {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','z','y'  ,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Z','Y' ,             };
static char[] c5= {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Z','Y' , 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','z','y',             '0','1','2','3','4','5','6','7','8','9'};


static List<char[]> cs = new ArrayList<char[]>(){ 
	private static final long serialVersionUID = 1L;
{this.add(c1);this.add(c2);this.add(c3);this.add(c4);this.add(c5);}};


public static  void  main(String ...strings ) throws IOException{
	long dd= System.currentTimeMillis();
	 
	List<String> keys =   getLenkeys(str,1009999);
	//System.out.println("--------------pos------------"+keys);
	
	FileWriter fw =new FileWriter("D:/tt.txt");
	for(String str : keys){
		//System.out.println("-------------str----------"+str);
		fw.write(str+"\n");
	};
	fw.close();
	System.out.println("----------------"  );
	System.out.println((System.currentTimeMillis()-dd)  );
};

public static int IndexPostion(char c ,char[] source){
	for(int i = 0 ; i<source.length;i++){
		if(c==source[i]){
			return i;
		}
	}
	return 0;
}

/**
 * @param init 初始的 字符串
 * @param len 需要多少个
 * @return
 */
public static List<String> getLenkeys(String init ,int len){
	List<String> keys = new ArrayList<String>();
	char[] charq = str.toCharArray();
	boolean loop =true;
	int leng = 0;
	int pos = charq.length-1 ;
	int cpos = -1;
	while(loop){
		int i =   IndexPostion(charq[pos],cs.get(pos));
		if(leng == (pos) ){
			loop = false;
		}
		if(61==i){
			pos--;
			continue;
		}else{
			cpos = pos;
			break;
		}
	};
	//使用完了后  重新来一轮
	if(cpos ==-1){
		for(int i = 0 ; i < charq.length;i++){
			charq[i] = cs.get(i)[0];
		}
	}else{
		// ok
	};
	for(int i  =0 ; i < len ;i++){
		char[] temp = charsAddOne(charq, cpos);
		//System.out.println(temp);
		keys.add(new String(temp));
	};
	
	return keys;
};

private static char[] charsAddOne(char[] squ, final int pos){
	//List<String> creatSeq = new ArrayList<String>();
	if(pos>squ.length || pos <0){
		return null;
	}
	char c = squ[pos];
	
	int squpos = IndexPostion(  c ,cs.get(pos));
	
	if(squpos == 61){
		squ[pos] = 	cs.get(pos)[squpos];
		//
		for(int o = pos ; o<squ.length ;o++){
			System.out.println(o);
			squ[o] = cs.get(o)[0];
		};
		squ = charsAddOne(  squ,  pos-1);
		
	}else{
		squ[pos] = 	cs.get(pos)[squpos+1];
	}
	return squ;
};

}
